<template>
  <div class="chart-card" :class="{ 'chart-card-loading': loading }">
    <div class="chart-card-header">
      <div class="chart-card-title">
        <slot name="title">{{ title }}</slot>
      </div>
      <div v-if="$slots.extra" class="chart-card-extra">
        <slot name="extra"></slot>
      </div>
    </div>
    
    <div class="chart-card-content">
      <div v-if="$slots.data" class="chart-card-data">
        <slot name="data"></slot>
      </div>
      
      <div v-if="loading" class="chart-card-loading-content">
        <div class="chart-card-loading-icon"></div>
      </div>
      <slot></slot>
    </div>
    
    <div v-if="$slots.footer" class="chart-card-footer">
      <slot name="footer"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ChartCard',
  props: {
    title: {
      type: String,
      default: ''
    },
    loading: {
      type: Boolean,
      default: false
    }
  }
}
</script>

<style scoped>
.chart-card {
  position: relative;
  padding: 16px;
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  height: 100%;
  display: flex;
  flex-direction: column;
}

.chart-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.chart-card-title {
  font-size: 16px;
  color: #333;
  font-weight: 500;
}

.chart-card-extra {
  color: #999;
}

.chart-card-content {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.chart-card-data {
  margin-bottom: 12px;
}

.chart-card-footer {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #f0f0f0;
  color: #999;
  font-size: 14px;
}

.chart-card-loading-content {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(255, 255, 255, 0.6);
  z-index: 10;
}

.chart-card-loading-icon {
  width: 24px;
  height: 24px;
  border: 2px solid rgba(24, 144, 255, 0.2);
  border-top: 2px solid #1890ff;
  border-radius: 50%;
  animation: chart-card-loading 1s infinite linear;
}

@keyframes chart-card-loading {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
</style> 